#include <iostream>
using namespace std;

int FindGreatestSumOfSubArray(int *pData, int nLength)
{
	int nCurSum = 0;
	int nGreatestSum = 0x80000000;
	for(int i = 0; i < nLength; ++i)
	{
		if(nCurSum <= 0)
			nCurSum = pData[i];
		else
			nCurSum += pData[i];

		if(nCurSum > nGreatestSum)
			nGreatestSum = nCurSum;
	}

	return nGreatestSum;
} 



int Greatsumofsubarray(int *a, int length)
{

	int sum=0;
	int greatsum=0x80000000;
    for (int i=0;i<length;i++)
    {
		if (sum<=0)
		{
			sum=a[i];
		}
		else
		{
			sum+=a[i];
		}

		if (sum>greatsum)
		{
			greatsum=sum;
		}
    }
	return greatsum;
}



int GetGreatSumofsubarray(int *a, int length)
{
	int sum=0;
	int greatsum=0;
	for (int i=0;i<length;i++)
	{
		if (sum<0)
		{
			sum=a[i];
		}
		else
			sum+=a[i];
		if (sum>greatsum)
		{
			greatsum=sum;
		}
	}
	return greatsum;
}



int main()
{
	int a[]={1, -2, 3, 10, -4, 7, 2, 5};
	int len=sizeof(a)/sizeof(a[0]);
	int result=Greatsumofsubarray(a,len);
	cout<<result<<endl;
	return 0;
}